{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import openpyxl\n",
    "myBook=openpyxl.load_workbook('收入表.xlsx')\n",
    "mySheet=myBook['收入表']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "myNewBook=openpyxl.Workbook()\n",
    "myNewSheet=myNewBook.active\n",
    "myNewSheet.title='收入表'\n",
    "myNewSheet.append(['季度','业务类别','营业收入'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "myRange1=mySheet['A'][4:]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1季度 家电收入 296719\n",
      "1季度 建材收入 203358\n",
      "1季度 其他收入 5613\n",
      "2季度 家电收入 373445\n",
      "2季度 建材收入 138815\n",
      "2季度 其他收入 445\n",
      "3季度 家电收入 496008\n",
      "3季度 建材收入 168123\n",
      "3季度 其他收入 1246\n",
      "4季度 家电收入 120234\n",
      "4季度 建材收入 499028\n",
      "4季度 其他收入 118896\n"
     ]
    }
   ],
   "source": [
    "myRange2=mySheet.iter_rows(min_col=2,min_row=5)\n",
    "for myQuater,myRow in zip(myRange1,myRange2):\n",
    "    for myType,myAmount in zip(mySheet['4'][1:],myRow):\n",
    "        print(myQuater.value,myType.value,myAmount.value)\n",
    "        myNewSheet.append([myQuater.value,myType.value,myAmount.value])\n",
    "myNewBook.save('结果表-收入表.xlsx')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
